<?php
$isReloadable = false;
require_once("../../../pers/inc.config.php");
require_once('../../_inc/inc.session.php');
require_once('../../_inc/funct.html.php');
require_once('../../_inc/funct.getFiles.php');

$sql_sel = "SELECT m.cod_modulo, m.descr as m_descr "
		.", r.* "
		." FROM wfm_regole r " 
		." LEFT JOIN wfm_moduli m ON r.id_modulo = m.id_modulo "
		." WHERE r.id_regola = ".reqVarInt('id');
$objDB->query($sql_sel,'selRec');
if(!$aRow = $objDB->fetch('selRec')) {
	die("id. errato");
}

$script = $aRow['script'];

if (reqVar('azione')=='scarinst') {
	$pathReg = OVF_FS_WEB_ROOT."/pers/wfma/".$aRow['cod_modulo']
		."/reg".$aRow['tipo_regola']."_".$aRow['cod_regola'].".php";
	if (file_exists($pathReg)) {
		$script = file_get_contents($pathReg);
	} else {
		$script = "<?php\r\n"
			."function reg".$aRow['tipo_regola']."_".$aRow['cod_regola']
			."(&\$aDatiInp,&\$aDatiDB,\$comando='') {\r\n\r\n}\r\n";
	}
}

$fileName = "reg".$aRow['tipo_regola']."_".$aRow['cod_regola'].".php";
headerDownLoad(strlen($script), $fileName);
echo $script;
exit;